<?php

namespace app\model;

use think\facade\Db;
use think\Model;

class UserReadingRecordsModel extends Model {

    protected $table ="user_reading_records";

    protected $pk = 'read_record_id';


    /*
   * 获取total
   * */
    public function getTotal($where=[]){
        return Db::name($this->table)->where($where)->count();
    }


    /*
     * 获取list
     * */
    public function getList($where=[],$page = null,$limit = null,$orderField = null,$orderType = "ASC"){

        $obj =  Db::name($this->table)->where($where);


        if(!empty($page) && !empty($limit)){
            $obj = $obj->page($page, $limit);
        }

        if(!empty($orderField) && !empty($orderType)){
            $obj = $obj->order($orderField, $orderType);
        }

        return $obj->select()->toArray();
    }



    /*
     * 删除操作
     * */
    public function delAll($where){
        return Db::name($this->table)->where($where)->delete();
    }




    /*
     * 增加或更新用户搜索记录
     *
     * */
    public function addOne($data){
        return Db::name($this->table)->insertGetId($data);
    }

    /*
   * 增加或更新用户搜索记录
   *
   * */
    public function updateOne($where,$data){
        return Db::name($this->table)->where($where)->update($data);
    }

}